/**
 * Copyright &copy; 2012-2016 <a href="https://github.com/thinkgem/jeesite">JeeSite</a> All rights reserved.
 */
package com.thinkgem.jeesite.modules.hk.sys.web.job;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.thinkgem.jeesite.common.config.Global;
import com.thinkgem.jeesite.common.persistence.Page;
import com.thinkgem.jeesite.common.web.BaseController;
import com.thinkgem.jeesite.common.utils.StringUtils;
import com.thinkgem.jeesite.modules.hk.sys.entity.job.HkUserEnterpriseRecruit;
import com.thinkgem.jeesite.modules.hk.sys.service.job.HkUserEnterpriseRecruitService;

/**
 * 企业招聘信息Controller
 * @author 罗天文
 * @version 2018-06-15
 */
@Controller
@RequestMapping(value = "${adminPath}/sys/job/hkUserEnterpriseRecruit")
public class HkUserEnterpriseRecruitController extends BaseController {

	@Autowired
	private HkUserEnterpriseRecruitService hkUserEnterpriseRecruitService;
	
	@ModelAttribute
	public HkUserEnterpriseRecruit get(@RequestParam(required=false) String id) {
		HkUserEnterpriseRecruit entity = null;
		if (StringUtils.isNotBlank(id)){
			entity = hkUserEnterpriseRecruitService.get(id);
		}
		if (entity == null){
			entity = new HkUserEnterpriseRecruit();
		}
		return entity;
	}
	
	@RequiresPermissions("sys:job:hkUserEnterpriseRecruit:view")
	@RequestMapping(value = {"list", ""})
	public String list(HkUserEnterpriseRecruit hkUserEnterpriseRecruit, HttpServletRequest request, HttpServletResponse response, Model model) {
		Page<HkUserEnterpriseRecruit> page = hkUserEnterpriseRecruitService.findPage(new Page<HkUserEnterpriseRecruit>(request, response), hkUserEnterpriseRecruit); 
		model.addAttribute("page", page);
		return "hk/sys/job/hkUserEnterpriseRecruitList";
	}

	@RequiresPermissions("sys:job:hkUserEnterpriseRecruit:view")
	@RequestMapping(value = "form")
	public String form(HkUserEnterpriseRecruit hkUserEnterpriseRecruit, Model model) {
		model.addAttribute("hkUserEnterpriseRecruit", hkUserEnterpriseRecruit);
		return "hk/sys/job/hkUserEnterpriseRecruitForm";
	}

	@RequiresPermissions("sys:job:hkUserEnterpriseRecruit:edit")
	@RequestMapping(value = "save")
	public String save(HkUserEnterpriseRecruit hkUserEnterpriseRecruit, Model model, RedirectAttributes redirectAttributes) {
		if (!beanValidator(model, hkUserEnterpriseRecruit)){
			return form(hkUserEnterpriseRecruit, model);
		}
		hkUserEnterpriseRecruitService.save(hkUserEnterpriseRecruit);
		addMessage(redirectAttributes, "保存企业招聘信息成功");
		return "redirect:"+Global.getAdminPath()+"/sys/job/hkUserEnterpriseRecruit/?repage";
	}
	
	@RequiresPermissions("sys:job:hkUserEnterpriseRecruit:edit")
	@RequestMapping(value = "delete")
	public String delete(HkUserEnterpriseRecruit hkUserEnterpriseRecruit, RedirectAttributes redirectAttributes) {
		hkUserEnterpriseRecruitService.delete(hkUserEnterpriseRecruit);
		addMessage(redirectAttributes, "删除企业招聘信息成功");
		return "redirect:"+Global.getAdminPath()+"/sys/job/hkUserEnterpriseRecruit/?repage";
	}

}